package com.jintian.smart.kernel.autoconfigure.model;

import com.jintian.smart.kernel.core.constant.ModelConst;
import com.jintian.smart.kernel.core.jackson.OrmDatabindMoudle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * 多个ApplicationContext环境自动装配
 */
@Slf4j
@Configuration(proxyBeanMethods = false)
@EnableTransactionManagement
public class MultiApplicationContextStarter {
    @Bean
    Jackson2ObjectMapperBuilderCustomizer ormObjectMapperBuilderCustomizer() {
        return new Jackson2ObjectMapperBuilderCustomizer() {
            @Override
            public void customize(Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) {
                jacksonObjectMapperBuilder.postConfigurer((mapper) -> {
                    mapper.registerModule(new OrmDatabindMoudle());
                });
            }
        };
    }



// TODO 未集成交换部分，临时注释
//    @ConditionalOnProperty(name = "smart.switching.enable", havingValue = "true", matchIfMissing = false)
//    @ConditionalOnClass(name = "com.jintian.samrt.switching.runtime.ExtractJobAspect")
//    static class ExchangeConfiguration {
//        @Bean
//        ExtractJobAspect extractJobAspect() {
//            return new ExtractJobAspect();
//        }
//    }


    @Configuration(proxyBeanMethods = false)
    @ConditionalOnProperty(name = ModelConst.PROPERTY_SMART_MASTER, havingValue = "false", matchIfMissing = false)
    static class SlaveApplicationContext {

    }
}
